<template>
  <div class="app-container" style="display: flex">
    <el-card class="log_card" style="width: 50%">
        <el-button type="primary" class="log" :loading="isConcatLog" @click="concatLog">同步日志</el-button>
        <el-row type="flex" justify="center" :gutter="200">
        <el-col :span="21" v-if="concatLogList && concatLogList[0] !=null && concatLogList.length > 0" >
          <el-row  v-for="(item,index) of concatLogList"  class="text" :key="index">
            <el-col>{{index+1}}.{{item.taskName}}  </el-col>
            <el-col style=" margin-top: -20px;color: #888">
                {{item.taskTime}}  &nbsp;&nbsp;
                {{ index != 0 ? '更新：' : '' }}{{index != 0 ? (item.updateCount?item.updateCount:0)+';' : ''}}
                新增：{{item.insertCount?item.insertCount:0}};
                同步状态：{{item.success?'失败':'成功'}}
            </el-col>
          </el-row>
        </el-col>
      </el-row>
<!--        分割线-->
        <el-divider></el-divider>
        <el-button type="primary" class="log" :loading="isConcatUser" @click="concatUser">同步人员</el-button>
        <el-row type="flex" justify="center" :gutter="200">
        <el-col :span="21" v-if="concatUserList && concatUserList[0] !=null && concatUserList.length > 0 ">
          <el-row  class="text" v-for="(item,index) of concatUserList" :key="index">
            <el-col >{{index+1}}.{{item && item.taskName}}  </el-col>
            <el-col  style=" margin-top: -20px;color: #888"> {{item && item.taskTime}} &nbsp;&nbsp;
                更新：{{item && item.updateCount?item.updateCount:0}};
                新增：{{item.insertCount?item.insertCount:0}};  同步状态：{{item.success?'失败':'成功'}}
            </el-col>
          </el-row>
        </el-col>
      </el-row>
  </el-card>

      <!--        外派人员-->
      <el-card class="log_card" style="width: 50%;margin-left: 20px">
          <el-button type="primary" class="log" style="width: 200px" :loading="isConcatOther" @click="concatOtherLog">同步外包人员信息</el-button>
          <el-row type="flex" justify="center" :gutter="200">
              <el-col :span="21"  v-if="concatOther && concatOther[0] !=null && concatOther.length>0 ">
                  <el-row  v-for="(item,index) of concatOther"  class="text" :key="index">
                      <el-col>{{index+1}}.{{item.taskName}}  </el-col>
                      <el-col style=" margin-top: -20px;color: #888">
                          {{item.taskTime}}  &nbsp;&nbsp;
                          {{ index != 0 ? '更新：' : '' }}{{index != 0 ? (item.updateCount?item.updateCount:0)+';' : ''}}
                          新增：{{item.insertCount?item.insertCount:0}};
                          同步状态：{{item.success?'失败':'成功'}}
                      </el-col>
                  </el-row>
              </el-col>
          </el-row>
      </el-card>


      <el-dialog title="选择日期" :visible.sync="visibleFlag" width="450px" >
          <div style="text-align: center;margin-top: -20px" >
              <el-form :model="param" :rules="rules" ref="ruleForm" class="demo-ruleForm" :inline="true" :key="paramKey" >
                  <el-form-item prop="day" required label="日期：">
                      <el-date-picker
                              v-model="param.day"
                              type="date"
                              placeholder="请选择日志同步的日期"
                              format="yyyy-MM-dd"
                              value-format="yyyy-MM-dd"
                              style="width: 100%;">
                      </el-date-picker>
                  </el-form-item>

                  <el-form-item>
                      <el-button v-show="false" type="primary" @click="submitParam()"></el-button>
                  </el-form-item>
              </el-form>
          </div>
          <div slot="footer" class="dialog-footer" style="margin-top: -30px">
              <el-button @click="visibleFlag = false">取 消</el-button>
              <el-button type="primary" @click="doSure()" >确 定</el-button>
          </div>
      </el-dialog>

  </div>
</template>
<script>
import {
    http_role_concatLog,
    http_role_concatUser,
    http_role_lastConcatLog,
    http_role_lastConcatUser,
    http_task_concatOtherLog,
    http_task_concatLastOtherLog, http_role_concatLog_new, http_task_concatOtherLog_new
} from '@/api/systemLog'
  import {Message} from "element-ui";
  import { http_myLogs_export } from '@/api/myLog'
export default {
  name:"systemLog",
    data(){
      return {
          visibleFlag: false,
          type :null,
          isConcatLog: false,
          isConcatUser: false,
          concatLogList:[],
          concatUserList:[],
          concatOther: [],
          concatLastOther: [],
          isConcatOther: false,
          paramKey: Date.now(),
          param:{
              day: null,
          },
          rules: {
              day: [
                  {required: true, message: '请选择日志同步的日期', trigger: ['blur','change'] }
              ],
          }
      }
    },
    mounted(){
        this.lastConcatLog()
        this.lastConcatUser()
        this.concatLastOtherLog()
    },
    methods:{
        concatLog(){
            this.paramKey = Date.now()
            this.param.day = null
            this.type = 0
            this.visibleFlag = true
          // this.isConcatLog = true
          // http_role_concatLog().then((res)=>{
          //     this.concatLogList = res.data
          //     this.isConcatLog = false
          //     this.$message({
          //       message: '同步完成',
          //       type: 'success'
          //     })
          // }).catch(err => {
          //     this.isConcatLog = false
          // })
        },
        concatUser(){
          this.isConcatUser = true
          http_role_concatUser().then((res)=>{
              this.concatUserList = res.data
              this.isConcatUser = false
              this.$message({
                message: '同步完成',
                type: 'success'
              })
          }).catch(err => {
              this.isConcatUser = false
          })
        },
        lastConcatLog(){
            http_role_lastConcatLog().then((res)=>{
                this.concatLogList = res.data
            })
        },
        lastConcatUser(){
            http_role_lastConcatUser().then((res)=>{
                this.concatUserList = res.data
            })
        },
        concatOtherLog(){
            this.paramKey = Date.now()
            this.param.day = null
            this.type = 1
            this.visibleFlag = true
            // this.isConcatOther = true
            // http_task_concatOtherLog().then(result=>{
            //     const {data} = result
            //     this.concatOther = data
            //     Message.success("同步成功")
            //     this.isConcatOther = false
            // }).catch(error=>{
            //     this.isConcatOther = false
            // })
        },
        concatLastOtherLog(){
            http_task_concatLastOtherLog().then(result=>{
                const { data} = result
                this.concatOther = data
            })
        },
        http_concatLog_new(){
            this.isConcatLog = true
            http_role_concatLog_new(this.param.day).then((res)=>{
                this.concatLogList = res.data
                this.isConcatLog = false
                this.$message({
                  message: '同步完成',
                  type: 'success'
                })
            }).catch(err => {
                this.isConcatLog = false
            })
        },
        http_task_new(){
            this.isConcatOther = true
            http_task_concatOtherLog_new(this.param.day).then(result=>{
                const {data} = result
                this.concatOther = data
                Message.success("同步成功")
                this.isConcatOther = false
            }).catch(error=>{
                this.isConcatOther = false
            })
        },
        submitParam(type){
            this.$refs['ruleForm'].validate((valid) => {
                if (valid) {
                    this.visibleFlag = false
                    if (this.type == 0){
                        this.http_concatLog_new()
                    }else if(this.type == 1) {
                        this.http_task_new()
                    }
                    return true
                } else {
                    // console.log('error submit!!');
                    return false;
                }
            });
        },
        doSure(){
            this.submitParam()
        }
    },

}
</script>
<style scoped="scoped">
.sep{
  border-top: 1px dashed #ccc;
  margin: 25px;
}
.systemLog{
  padding: 40px;

}
  .log{
    cursor: pointer;
    height: 50px;
    width: 140px;
    background: #409EFF;
    text-align: center;
    font-size: 18px;
    /* line-height: 50px; */
    color: #fff;
    border-radius: 5px;
  }
  .text{
    font-size: 18px;
    line-height: 50px;
  }
  .log_card{
    padding: 20px 0;
  }
</style>
